﻿using SixLabors.ImageSharp;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace lingopen
{
    /// <summary>
    /// 图片转换类
    /// </summary>
    public static class ImageHelper
    {

        /// <summary>
        /// 生成缩略图
        /// </summary>
        /// <param name="image"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <returns></returns>
        public static byte[] Thumbnail(this byte[] input, int width, int height)
        {
            //byte[] ret = null; 
            //using (Image<Rgba32> image = Image.Load(input))
            //{
            //    image.Mutate(x => x
            //         .Resize(width, height)
            //         );
            //    using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
            //    {
            //        image.SaveAsPng(ms);
            //        ret = ms.ToArray();
            //    }
            //}
            //return ret;
            return input;
        }
        public static int[] GetSize(this Stream stream)
        {
            int w = 0;
            int h = 0;
            try
            {
                var img = Image.Load(stream);
                h = img.Height;
                w = img.Width;
                return new int[] { w, h };
            }
            catch (Exception)
            {
                return new int[] { w, h };
            }

        }

    }
}
